/**
 * @file demoModule/demo
 * @author flower.cheng(flower.cheng@boqii.com)
 */
import ApiConfig from '@/service/apiConfig';
import HttpService from '@/service/httpService';

const {
  demoNodeApi
} = ApiConfig;
export const state = () => {
    return {
        /**
         * @description 测试数据
         * @type {object}
         */
        demoData: {
            a: 1,
            b: 2
        },
        demoAmount: 100
    };
};

export const getters = {
    demoData: state => state.demoData,
    demoAmount: state => state.demoAmount
}

export const actions = {
    /**
     * 获取demo data
     * @param {}
     */
    getDemoData({
        commit,
        state
    }, params) {
        return new Promise((resolve, reject) => {
            HttpService.nodeCall(demoNodeApi, params).then(data => {
                resolve(data)
                commit(demoNodeApi.mutation, data)
            })
        })
    }
};

export const mutations = {
    [demoNodeApi.mutation](state, data) {
        state.demoData = data.data
        console.log('demo api call success', state, data)
    }
};
